<?php

/** -----------------------------------------------------------------
* 	ID:						$Id: split_page_results.php 2 2011-02-17 13:35:25Z akausch $
* 	Letzter Stand:			$Revision: 2 $
* 	zuletzt geändert von: 	$Author: akausch $
* 	Datum:					$Date: 2011-02-17 14:35:25 +0100 (Do, 17. Feb 2011) $
*
* 	commerce:SEO by Webdesign Erfurt
* 	http://www.commerce-seo.de
*
* 	Copyright (c) since 2010 commerce:SEO
* ------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* --------------------------------------------------------------- **/


/**
 * Die Klasse liefert diverse Methoden um abgefragte Seiten aufzubereiten.
 **/
class splitPageResults
{
    var $sql_query, $number_of_rows, $current_page_number, $number_of_pages, $number_of_rows_per_page, $current_category_id;

    /**
     * PHP4 Konstruktor
     * 
     * @see __construct()
     */
    public function splitPageResults($query, $page, $max_rows, $count_key = '*')
    {
    	$this->__construct($query, $page, $max_rows, $count_key);    	
    }
    
    /**
     * Der PHP5 Konstruktor der Klasse.
     * Initialisiert die abzufragenden Seiten mit diversen Parametern.
     *
     * @param string $query
     * @param int $page
     * @param int $max_rows
     * @param string $count_key
     */
	public function __construct($query, $page, $max_rows, $count_key = '*') 
	{
        $this->sql_query = $query;

        if ( empty($page) || (is_numeric($page) == false) ) {
            $page = 1;
        }

        
        $this->current_page_number = $page;

        $this->number_of_rows_per_page = $max_rows;

        $pos_to = strlen($this->sql_query);
        $pos_from = strpos($this->sql_query, ' FROM', 0);

        $pos_group_by = strpos($this->sql_query, ' GROUP BY', $pos_from);

        if ( ($pos_group_by < $pos_to) && ($pos_group_by != false) ) {
            $pos_to = $pos_group_by;
        }

        $pos_having = strpos($this->sql_query, ' HAVING', $pos_from);

        if ( ($pos_having < $pos_to) && ($pos_having != false) ) {
            $pos_to = $pos_having;
        }

        $pos_order_by = strpos($this->sql_query, ' ORDER BY', $pos_from);

        if ( ($pos_order_by < $pos_to) && ($pos_order_by != false) ) {
            $pos_to = $pos_order_by;
        }

        if(strpos($this->sql_query, 'DISTINCT') || strpos($this->sql_query, 'GROUP BY'))
            $count_string = 'DISTINCT ' . xtc_db_input($count_key);
        else
            $count_string = xtc_db_input($count_key);


        $count_query = xtDBquery($query);
        $count = xtc_db_num_rows($count_query, true);

        $this->number_of_rows = $count;
        $this->number_of_pages = ceil($this->number_of_rows / $this->number_of_rows_per_page);

        // Avoid indexing of non existing pages, excluding the first page
        // (e.g. if there are no reviews, allow review.php!)
        if (($page > 1) && ($page > $this->number_of_pages))
            header("HTTP/1.0 404 Not Found");

        if ($this->current_page_number > $this->number_of_pages)
            $this->current_page_number = $this->number_of_pages;

        $offset = $this->number_of_rows_per_page * ($this->current_page_number - 1);
        $offset = $offset < 0 ? 0 : $offset;

        $this->sql_query .= " LIMIT " . $offset . ", " . $this->number_of_rows_per_page;
    }

	/**
     * Diese Funktion erzeugt ein Array mit Links zur Navigation
	 * durch die Produkte, bei eingeschalteten SEO-Urls.
     *
     * @param int $max_page_links
     * @param mixed $parameters
     * @param string $text_output
     * @param string $active_site
     */	
    function getSEOLinksArray($max_page_links, $parameters = '', $text_output="", $active_site = '') {
        global $request_type;

/*		
		if ($_SESSION['view_as'] != '') {
        $parameters = '&view_as='.$_SESSION['view_as'];
		}
#		if ($_SESSION['per_site']) {
#        $parameters .= '&'.$_SESSION['per_site'];
#		}
		if ($_GET['multisort'] != '') {
        $parameters .= '&multisort='.$_GET['multisort'];
		}
		if ($_GET['filter_id'] != '') {
        $parameters .= '&filter_id='.$_GET['filter_id'];
		}
*/
        $this->current_category_id = $_GET['cPath'];

        $start = $this->current_page_number - $max_page_links;
        $start = $start < 1 ? 1 : $start;

        $end = $this->current_page_number + $max_page_links;
        $end = $end > $this->number_of_pages ? $this->number_of_pages : $end;

        $links = array();

		$site = '&page=';

		$url = FILENAME_DEFAULT;

        // zurück Button - wird auf der ersten Seite nicht angezeigt
        if ( $this->current_page_number > 1 ) {
            if ($this->current_page_number == 2) {
                if ($_GET['manufacturers_id'] != '') {
					$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']).$parameters;
				} else {
					$href = xtc_href_link($url, 'cPath='.$this->current_category_id).$parameters;
				}
            } else {
				if ($_GET['manufacturers_id'] != '') {
					$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']). $site . ($this->current_page_number - 1) . $parameters;
				} else {
					$href = xtc_href_link($url, 'cPath='.$this->current_category_id). $site . ($this->current_page_number - 1) . $parameters;
				}
			}

            $links['previous_button'] = array('title' => PREVNEXT_TITLE_PREVIOUS_PAGE,
                                              'href'  => $href,
                                              'name'  => PREVNEXT_BUTTON_PREV);

			//link: erste seite:
			if ($_GET['manufacturers_id'] != '') {
				$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id'], $parameters , $request_type);
			} else {
				$href = xtc_href_link($url, 'cPath='.$this->current_category_id) .  $parameters;
			}

            $links['first_page'] = array('title' => PREVNEXT_TITLE_FIRST_PAGE,
                                         'href'  => $href,
                                         'name'  => 1);
        }

		//link: letzte seite:
        if ( $this->current_page_number < $this->number_of_pages ) {
			if ($_GET['manufacturers_id'] != '') {
				$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']). $site . $this->number_of_pages . $parameters;
			} else {
				$href = xtc_href_link($url, 'cPath='.$this->current_category_id). $site . $this->number_of_pages . $parameters;
			}

            $links['last_page'] = array('title' => PREVNEXT_TITLE_LAST_PAGE,
                                         'href'  => $href,
                                         'name'  => $this->number_of_pages);
        }
        // vorwärts Button
        if ( $this->current_page_number < $this->number_of_pages && $this->number_of_pages != 1 ) {
			if ($_GET['manufacturers_id'] != '') {
				$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']). $site . ($this->current_page_number + 1) . $parameters;
			} else {
				$href = xtc_href_link($url, 'cPath='.$this->current_category_id). $site . ($this->current_page_number + 1) . $parameters;
            }
			
            $links['next_button'] = array('title' => PREVNEXT_TITLE_NEXT_PAGE,
                                          'href'  => $href,
                                          'name'  => PREVNEXT_BUTTON_NEXT);
        }

        // check if number_of_pages > $max_page_links
        $cur_window_num = intval($this->current_page_number / $max_page_links);

        if ($this->current_page_number % $max_page_links) {
            $cur_window_num++;
        }

        $max_window_num = intval($this->number_of_pages / $max_page_links);

        if ($this->number_of_pages % $max_page_links) {
            $max_window_num++;
        }

        // previous window of pages
        if ( $cur_window_num > 1 ) {
			$href = xtc_href_link($url , 'cPath='.$this->current_category_id). $site . (($cur_window_num - 1) * $max_page_links) . $parameters;


            $links['previous_window'] = array('title' => PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE,
                                              'href'  => $href,
                                              'name'  => $max_page_links);
        }

		if($this->number_of_pages > 1)
			$_SESSION['template']['current_url']  = xtc_href_link($url, 'cPath='.$this->current_category_id) . $site . $this->current_page_number . $parameters;
		else
			unset($_SESSION['template']['current_url']);

        // Seiten Anzeige (Mitte):
        if ( $end > 1 ) {
            for ( $cur = $start; $cur <= $end; $cur++ ) {
                if ($cur == $this->current_page_number) {
                    $links['pages'][] = array('title' => '',
                                              'href'  => '',
                                              'name'  => $cur);
                } else {
                    if ($cur == 1) {// avoid DC through page=1
						if ($_GET['manufacturers_id'] != '') {
							$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']) . $parameters;
						} else {
							$href = xtc_href_link($url, 'cPath='.$this->current_category_id) . $parameters;
						}						
						
                    } else {
						if ($_GET['manufacturers_id'] != '') {
							$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']). $site . $cur . $parameters;
						} else {
							$href = xtc_href_link($url, 'cPath='.$this->current_category_id). $site . $cur . $parameters;
						}
					}

                    $links['pages'][] = array('title' => sprintf(PREVNEXT_TITLE_PAGE_NO, $cur),
                                              'href'  => $href,
                                              'name'  => $cur);
                }
            }
        }

        // next window of pages
        if ($cur_window_num < $max_window_num) {

            $href = xtc_href_link($url, 'cPath='.$this->current_category_id). $site . (($cur_window_num) * $max_page_links + 1) . $parameters;

            $links['next_window'] = sprintf('<a href="%s" title="%s">...</a>', $href, sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links));
        }

        $links['current_page'] = $this->current_page_number;
        $links['total'] = $this->display_count($text_output);

        return $links;
    }

/** NOTICE BY N.SOELLINGER: OLD BUGGY VERSION OF THE METHOD!
 
**/

/**
 * Diese Funktion erzeugt ein Array mit Links zur Navigation durch die Produkte.
 *
 * @param int $max_page_links
 * @param mixed $parameters
 * @param string $text_output
 * @param string $active_site
 * @param bool $no_seo
 * @return mixed array()
 */
public function getLinksArray($max_page_links, $parameters = '', $text_output="", $active_site = '', $no_seo = false) {

	global $request_type;

	$PHP_SELF = $_SERVER['PHP_SELF'];
	
	$this->current_category_id = $_GET['cPath'];

	$start = $this->current_page_number - $max_page_links;
	$start = $start < 1 ? 1 : $start;

	$end = $this->current_page_number + $max_page_links;
	$end = $end > $this->number_of_pages ? $this->number_of_pages : $end;
	
	$links = array();
	
	$site = 'page=';
	

	if ($_GET['fcat'] != '') {
		$url = FILENAME_PRODUCT_FILTER;
	} else {
		$url = FILENAME_DEFAULT;
	}

	// zurueck Button - wird auf der ersten Seite nicht angezeigt
	if ( $this->current_page_number > 1 ) {
		if ($this->current_page_number == 2) {
			if ($_GET['manufacturers_id'] != '') {
				$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']."&page=".($this->current_page_number -1) . $parameters);
			} else if ($_GET['fcat'] != '') {
				$href = xtc_href_link($url, $parameters, $request_type);
			} else {
				$href = xtc_href_link($url."?cPath=".$this->current_category_id."&page=".($this->current_page_number -1) . $parameters);
			}
		}
		else
		{
				if ($_GET['manufacturers_id'] != '') {
					$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']."&page=" . ($this->current_page_number - 1) . $parameters);
				} else if ($_GET['fcat'] != '') {
					$href = xtc_href_link($url, $parameters."page=" . ($this->current_page_number - 1));
				} else {
					$href = xtc_href_link($url."?cPath=".$this->current_category_id."&page=" . ($this->current_page_number - 1) . $parameters);
				}

		}
		
		$links['previous_button'] = array('title' => PREVNEXT_TITLE_PREVIOUS_PAGE,
										'href'  => $href,
										'name'  => PREVNEXT_BUTTON_PREV);
		
		//link: erste seite:
		if ($_GET['manufacturers_id'] != '') {
			$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']."&page=1" . $parameters);
		} elseif ($_GET['fcat'] != '') {
			$href = xtc_href_link($url, $parameters."page=1" , $request_type);
		} else {
			$href = xtc_href_link($url."?cPath=".$this->current_category_id."&page=1" . $parameters);
		}
		$links['first_page'] = array('title' => PREVNEXT_TITLE_FIRST_PAGE,
									'href'  => $href,
									'name'  => 1);
	}//if

        
	if ( $this->current_page_number < $this->number_of_pages )
	{
			if ($_GET['manufacturers_id'] != '') {
				$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id'] . $parameters . $site . $this->number_of_pages);
			} else {
				$href = xtc_href_link($url."?cPath=".$this->current_category_id."" . '&' . $site . $this->number_of_pages . $parameters);
			}
	        $links['last_page'] = array('title' => PREVNEXT_TITLE_LAST_PAGE,
                                     'href'  => $href,
                                     'name'  => $this->number_of_pages);
    }
	// vorwaerts Button
	if ( $this->current_page_number < $this->number_of_pages && $this->number_of_pages != 1 ) {
            if ($_GET['manufacturers_id'] != '') {
				$href = xtc_href_link($url."?manufacturers_id=".$_GET['manufacturers_id']."&page=".($this->current_page_number +1) . $parameters);
			} elseif ($_GET['fcat'] != '') {
				$href = xtc_href_link($url, $parameters."page=".($this->current_page_number +1), $request_type);
			} else {
				$href = xtc_href_link($url."?cPath=".$this->current_category_id."&page=".($this->current_page_number +1) . $parameters);
            }
			$links['next_button'] = array('title' => PREVNEXT_TITLE_NEXT_PAGE,
                                                'href'  => $href,
                                                'name'  => PREVNEXT_BUTTON_NEXT);
	}
	
	// check if number_of_pages > $max_page_links
	$cur_window_num = intval($this->current_page_number / $max_page_links);
	
	if ($this->current_page_number % $max_page_links)
		$cur_window_num++;
	
	$max_window_num = intval($this->number_of_pages / $max_page_links);
	
	if ($this->number_of_pages % $max_page_links)
		$max_window_num++;

	
	// previous window of pages
	if ( $cur_window_num > 1 ) {
		$href = xtc_href_link($url , $parameters . $site . (($cur_window_num - 1) * $max_page_links), $request_type);
		
		$links['previous_window'] = array('title' => PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE,
                                                    'href'  => $href,
                                                    'name'  => $max_page_links);
	}
	
	if($this->number_of_pages > 1)
		$_SESSION['template']['current_url']  = $url . $parameters . $site . $this->current_page_number;
	else
		unset($_SESSION['template']['current_url']);
	
	// Seiten Anzeige (Mitte):
	if ( $end > 1 ) {
        //cPath an url anhaengen

		if ($this->current_category_id != '') {
			$url .= "?cPath=".$this->current_category_id;
		} else {
			if ($_GET['manufacturers_id'] != '') {
				$url .= "?manufacturers_id=".$_GET['manufacturers_id'];
			}
		}
		
        for ( $cur = $start; $cur <= $end; $cur++ ) {
			if ($cur == $this->current_page_number) {
				$links['pages'][] = array('title' => '',
										'href'  => '',
										'name'  => $cur);
			} else {
                    if ($cur == 1) {	// avoid DC through page=1
						$href = xtc_href_link($url, $parameters, $request_type);
                    } else {
                        if ($_GET['fcat'] != '') {
							$href = xtc_href_link(FILENAME_PRODUCT_FILTER . $parameters.$site.$cur);
						} else {
							$href = xtc_href_link($url . '&' . $parameters.$site.$cur);
						}
                    }

                    $links['pages'][] = array('title' => sprintf(PREVNEXT_TITLE_PAGE_NO, $cur),
                                            'href'  => $href,
                                            'name'  => $cur);
                }
            }//for
	}

	// next window of pages
	if ($cur_window_num < $max_window_num) {		
		$href = xtc_href_link($url . $site . (($cur_window_num) * $max_page_links + 1), $parameters, $request_type);

	    $links['next_window'] = sprintf('<a href="%s" title="%s">...</a>',
								        $href,
								        sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links));
	}
	
	$links['current_page'] = $this->current_page_number;
	$links['total'] = $this->display_count($text_output);
	
	return $links;
}
    
    function getLinksArrayTag($max_page_links, $parameters = '', $text_output, $active_site = '', $tag)
	{
        global $request_type;

        $PHP_SELF = $_SERVER['PHP_SELF'];

        $start = $this->current_page_number - $max_page_links;
        $start = $start < 1 ? 1 : $start;

        $end = $this->current_page_number + $max_page_links;
        $end = $end > $this->number_of_pages ? $this->number_of_pages : $end;

        $links = array();

		if($parameters !='' && (substr($parameters, -1) != '&'))
    		$parameters .= '&';
		$site = 'page=';

		$url = 'tag/'.$tag;

        // zurück Button - wird auf der ersten Seite nicht angezeigt
        if ( $this->current_page_number > 1 ) {

            if ($this->current_page_number == 2)
                $href = xtc_href_link($url, $parameters, $request_type);
            else
				$href = xtc_href_link($url, $parameters.$site . ($this->current_page_number - 1),$request_type);


            $links['previous_button'] = array('title' => PREVNEXT_TITLE_PREVIOUS_PAGE,
                                              'href'  => $href,
                                              'name'  => PREVNEXT_BUTTON_PREV);

            $href = xtc_href_link($url, $parameters , $request_type);

            $links['first_page'] = array('title' => PREVNEXT_TITLE_FIRST_PAGE,
                                         'href'  => $href,
                                         'name'  => 1);
        }

        if ( $this->current_page_number < $this->number_of_pages ) {
			$href = xtc_href_link($url,$parameters . $site . $this->number_of_pages, $request_type);

            $links['last_page'] = array('title' => PREVNEXT_TITLE_LAST_PAGE,
                                         'href'  => $href,
                                         'name'  => $this->number_of_pages);
        }
        // vorwärts Button
        if ( $this->current_page_number < $this->number_of_pages && $this->number_of_pages != 1 ) {

        	$href = xtc_href_link($url, $parameters . $site . ($this->current_page_number + 1), $request_type);

            $links['next_button'] = array('title' => PREVNEXT_TITLE_NEXT_PAGE,
                                          'href'  => $href,
                                          'name'  => PREVNEXT_BUTTON_NEXT);
        }

        // check if number_of_pages > $max_page_links
        $cur_window_num = intval($this->current_page_number / $max_page_links);

        if ($this->current_page_number % $max_page_links)
            $cur_window_num++;

        $max_window_num = intval($this->number_of_pages / $max_page_links);

        if ($this->number_of_pages % $max_page_links)
            $max_window_num++;

        // previous window of pages
        if($cur_window_num > 1) {
			$href = xtc_href_link($url , $parameters . $site . (($cur_window_num - 1) * $max_page_links), $request_type);

            $links['previous_window'] = array('title' => PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE,
                                              'href'  => $href,
                                              'name'  => $max_page_links);
        }

		if($this->number_of_pages > 1)
			$_SESSION['template']['current_url']  = $url . $parameters . $site . $this->current_page_number;
		else
			unset($_SESSION['template']['current_url']);

        // page nn button
        if ( $end > 1 ) {
            for ( $cur = $start; $cur <= $end; $cur++ ) {
                if ($cur == $this->current_page_number) {
                    $links['pages'][] = array('title' => '',
                                              'href'  => '',
                                              'name'  => $cur);
                } else {
                    if ($cur == 1) // avoid DC through page=1
						$href = xtc_href_link($url, $parameters, $request_type);
                   	else
						$href = xtc_href_link($url , $parameters . $site . $cur, $request_type);

                    $links['pages'][] = array('title' => sprintf(PREVNEXT_TITLE_PAGE_NO, $cur),
                                              'href'  => $href,
                                              'name'  => $cur);
                }
            }
        }

        // next window of pages
        if ($cur_window_num < $max_window_num) {

            $href = xtc_href_link($url . $site . (($cur_window_num) * $max_page_links + 1), $parameters, $request_type);

            $links['next_window'] = sprintf('<a href="%s" title="%s">...</a>',
                $href,
                sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links));
        }

        $links['current_page'] = $this->current_page_number;
        $links['total'] = $this->display_count($text_output);

        return $links;
    }

    function getLinksArraySearch($max_page_links, $parameters = '', $text_output, $active_site = '', $keywords) {
        global $request_type;

        $PHP_SELF = $_SERVER['PHP_SELF'];

        $start = $this->current_page_number - $max_page_links;
        $start = $start < 1 ? 1 : $start;

        $end = $this->current_page_number + $max_page_links;
        $end = $end > $this->number_of_pages ? $this->number_of_pages : $end;

        $links = array();

		if($parameters !='' && (substr($parameters, -1) != '&'))
    		$parameters .= '&';
		$site = 'page=';

		$url = 'keywords/'.$keywords;

        // zurück Button - wird auf der ersten Seite nicht angezeigt
        if ( $this->current_page_number > 1 ) {

            if ($this->current_page_number == 2)
                $href = xtc_href_link($url, $parameters, $request_type);
            else
				$href = xtc_href_link($url, $parameters.$site . ($this->current_page_number - 1),$request_type);


            $links['previous_button'] = array('title' => PREVNEXT_TITLE_PREVIOUS_PAGE,
                                              'href'  => $href,
                                              'name'  => PREVNEXT_BUTTON_PREV);

            $href = xtc_href_link($url, $parameters , $request_type);

            $links['first_page'] = array('title' => PREVNEXT_TITLE_FIRST_PAGE,
                                         'href'  => $href,
                                         'name'  => 1);
        }

        if ( $this->current_page_number < $this->number_of_pages ) {
			$href = xtc_href_link($url,$parameters . $site . $this->number_of_pages, $request_type);

            $links['last_page'] = array('title' => PREVNEXT_TITLE_LAST_PAGE,
                                         'href'  => $href,
                                         'name'  => $this->number_of_pages);
        }
        // vorwärts Button
        if ( $this->current_page_number < $this->number_of_pages && $this->number_of_pages != 1 ) {

        	$href = xtc_href_link($url, $parameters . $site . ($this->current_page_number + 1), $request_type);

            $links['next_button'] = array('title' => PREVNEXT_TITLE_NEXT_PAGE,
                                          'href'  => $href,
                                          'name'  => PREVNEXT_BUTTON_NEXT);
        }

        // check if number_of_pages > $max_page_links
        $cur_window_num = intval($this->current_page_number / $max_page_links);

        if ($this->current_page_number % $max_page_links)
            $cur_window_num++;

        $max_window_num = intval($this->number_of_pages / $max_page_links);

        if ($this->number_of_pages % $max_page_links)
            $max_window_num++;

        // previous window of pages
        if($cur_window_num > 1) {
			$href = xtc_href_link($url , $parameters . $site . (($cur_window_num - 1) * $max_page_links), $request_type);

            $links['previous_window'] = array('title' => PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE,
                                              'href'  => $href,
                                              'name'  => $max_page_links);
        }

		if($this->number_of_pages > 1)
			$_SESSION['template']['current_url']  = $url . $parameters . $site . $this->current_page_number;
		else
			unset($_SESSION['template']['current_url']);

        // page nn button
        if ( $end > 1 ) {
            for ( $cur = $start; $cur <= $end; $cur++ ) {
                if ($cur == $this->current_page_number) {
                    $links['pages'][] = array('title' => '',
                                              'href'  => '',
                                              'name'  => $cur);
                } else {
                    if ($cur == 1) // avoid DC through page=1
						$href = xtc_href_link($url, $parameters, $request_type);
                   	else
						$href = xtc_href_link($url , $parameters . $site . $cur, $request_type);

                    $links['pages'][] = array('title' => sprintf(PREVNEXT_TITLE_PAGE_NO, $cur),
                                              'href'  => $href,
                                              'name'  => $cur);
                }
            }
        }

        // next window of pages
        if ($cur_window_num < $max_window_num) {

            $href = xtc_href_link($url . $site . (($cur_window_num) * $max_page_links + 1), $parameters, $request_type);

            $links['next_window'] = sprintf('<a href="%s" title="%s">...</a>',
                $href,
                sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links));
        }

        $links['current_page'] = $this->current_page_number;
        $links['total'] = $this->display_count($text_output);

        return $links;
    }

	
    function getLinksArrayFilter($max_page_links, $parameters = '', $text_output, $active_site = '') {
        global $request_type;

        $PHP_SELF = $_SERVER['PHP_SELF'];

        $start = $this->current_page_number - $max_page_links;
        $start = $start < 1 ? 1 : $start;

        $end = $this->current_page_number + $max_page_links;
        $end = $end > $this->number_of_pages ? $this->number_of_pages : $end;

        $links = array();

		#if($parameters !='' && (substr($parameters, -1) != '&'))
    		$parameters .= '&';
		$site = 'page=';

		$url = FILENAME_PRODUCT_FILTER.'?request';

        // zurück Button - wird auf der ersten Seite nicht angezeigt
        if ( $this->current_page_number > 1 ) {

            if ($this->current_page_number == 2)
                $href = xtc_href_link($url . $parameters);
            else
				$href = xtc_href_link($url . $parameters . $site . ($this->current_page_number - 1));


            $links['previous_button'] = array('title' => PREVNEXT_TITLE_PREVIOUS_PAGE,
                                              'href'  => $href,
                                              'name'  => PREVNEXT_BUTTON_PREV);

            $href = xtc_href_link($url . $parameters);

            $links['first_page'] = array('title' => PREVNEXT_TITLE_FIRST_PAGE,
                                         'href'  => $href,
                                         'name'  => 1);
        }

        if ( $this->current_page_number < $this->number_of_pages ) {
			$href = xtc_href_link($url . $parameters . $site . $this->number_of_pages);

            $links['last_page'] = array('title' => PREVNEXT_TITLE_LAST_PAGE,
                                         'href'  => $href,
                                         'name'  => $this->number_of_pages);
        }
        // vorwärts Button
        if ( $this->current_page_number < $this->number_of_pages && $this->number_of_pages != 1 ) {

        	$href = xtc_href_link($url. $parameters . $site . ($this->current_page_number + 1));

            $links['next_button'] = array('title' => PREVNEXT_TITLE_NEXT_PAGE,
                                          'href'  => $href,
                                          'name'  => PREVNEXT_BUTTON_NEXT);
        }

        // check if number_of_pages > $max_page_links
        $cur_window_num = intval($this->current_page_number / $max_page_links);

        if ($this->current_page_number % $max_page_links)
            $cur_window_num++;

        $max_window_num = intval($this->number_of_pages / $max_page_links);

        if ($this->number_of_pages % $max_page_links)
            $max_window_num++;

        // previous window of pages
        if($cur_window_num > 1) {
			$href = xtc_href_link($url . $parameters . $site . (($cur_window_num - 1) * $max_page_links), $request_type);

            $links['previous_window'] = array('title' => PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE,
                                              'href'  => $href,
                                              'name'  => $max_page_links);
        }

		if($this->number_of_pages > 1)
			$_SESSION['template']['current_url']  = $url . $parameters . $site . $this->current_page_number;
		else
			unset($_SESSION['template']['current_url']);

        // page nn button
        if ( $end > 1 ) {
            for ( $cur = $start; $cur <= $end; $cur++ ) {
                if ($cur == $this->current_page_number) {
                    $links['pages'][] = array('title' => '',
                                              'href'  => '',
                                              'name'  => $cur);
                } else {
                    if ($cur == 1) // avoid DC through page=1
						$href = xtc_href_link($url . $parameters);
                   	else
						$href = xtc_href_link($url . $parameters . $site . $cur);

                    $links['pages'][] = array('title' => sprintf(PREVNEXT_TITLE_PAGE_NO, $cur),
                                              'href'  => $href,
                                              'name'  => $cur);
                }
            }
        }

        // next window of pages
        if ($cur_window_num < $max_window_num) {

            $href = xtc_href_link($url . $site . (($cur_window_num) * $max_page_links + 1), $parameters);

            $links['next_window'] = sprintf('<a href="%s" title="%s">...</a>',
                $href,
                sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links));
        }

        $links['current_page'] = $this->current_page_number;
        $links['total'] = $this->display_count($text_output);

        return $links;
    }

	//Reviews Pagenavigation
    function getLinksArrayReviews($max_page_links, $parameters = '', $text_output, $active_site = '')
	{
        global $request_type;

        $PHP_SELF = $_SERVER['PHP_SELF'];

        $start = $this->current_page_number - $max_page_links;
        $start = $start < 1 ? 1 : $start;

        $end = $this->current_page_number + $max_page_links;
        $end = $end > $this->number_of_pages ? $this->number_of_pages : $end;

        $links = array();

		if($parameters !='' && (substr($parameters, -1) != '&'))
    		$parameters .= '&';
		$site = 'page=';

		$url = FILENAME_REVIEWS;

        // zurück Button - wird auf der ersten Seite nicht angezeigt
        if ( $this->current_page_number > 1 ) {

            if ($this->current_page_number == 2)
                $href = xtc_href_link($url, $parameters, $request_type);
            else
				$href = xtc_href_link($url, $parameters.$site . ($this->current_page_number - 1),$request_type);


            $links['previous_button'] = array('title' => PREVNEXT_TITLE_PREVIOUS_PAGE,
                                              'href'  => $href,
                                              'name'  => PREVNEXT_BUTTON_PREV);

            $href = xtc_href_link($url, $parameters , $request_type);

            $links['first_page'] = array('title' => PREVNEXT_TITLE_FIRST_PAGE,
                                         'href'  => $href,
                                         'name'  => 1);
        }

        if ( $this->current_page_number < $this->number_of_pages ) {
			$href = xtc_href_link($url,$parameters . $site . $this->number_of_pages, $request_type);

            $links['last_page'] = array('title' => PREVNEXT_TITLE_LAST_PAGE,
                                         'href'  => $href,
                                         'name'  => $this->number_of_pages);
        }
        // vorwärts Button
        if ( $this->current_page_number < $this->number_of_pages && $this->number_of_pages != 1 ) {

        	$href = xtc_href_link($url, $parameters . $site . ($this->current_page_number + 1), $request_type);

            $links['next_button'] = array('title' => PREVNEXT_TITLE_NEXT_PAGE,
                                          'href'  => $href,
                                          'name'  => PREVNEXT_BUTTON_NEXT);
        }

        // check if number_of_pages > $max_page_links
        $cur_window_num = intval($this->current_page_number / $max_page_links);

        if ($this->current_page_number % $max_page_links)
            $cur_window_num++;

        $max_window_num = intval($this->number_of_pages / $max_page_links);

        if ($this->number_of_pages % $max_page_links)
            $max_window_num++;

        // previous window of pages
        if($cur_window_num > 1) {
			$href = xtc_href_link($url , $parameters . $site . (($cur_window_num - 1) * $max_page_links), $request_type);

            $links['previous_window'] = array('title' => PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE,
                                              'href'  => $href,
                                              'name'  => $max_page_links);
        }

		if($this->number_of_pages > 1)
			$_SESSION['template']['current_url']  = $url . $parameters . $site . $this->current_page_number;
		else
			unset($_SESSION['template']['current_url']);

        // page nn button
        if ( $end > 1 ) {
            for ( $cur = $start; $cur <= $end; $cur++ ) {
                if ($cur == $this->current_page_number) {
                    $links['pages'][] = array('title' => '',
                                              'href'  => '',
                                              'name'  => $cur);
                } else {
                    if ($cur == 1) // avoid DC through page=1
						$href = xtc_href_link($url, $parameters, $request_type);
                   	else
						$href = xtc_href_link($url , $parameters . $site . $cur, $request_type);

                    $links['pages'][] = array('title' => sprintf(PREVNEXT_TITLE_PAGE_NO, $cur),
                                              'href'  => $href,
                                              'name'  => $cur);
                }
            }
        }

        // next window of pages
        if ($cur_window_num < $max_window_num) {

            $href = xtc_href_link($url . $site . (($cur_window_num) * $max_page_links + 1), $parameters, $request_type);

            $links['next_window'] = sprintf('<a href="%s" title="%s">...</a>',
                $href,
                sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links));
        }

        $links['current_page'] = $this->current_page_number;
        $links['total'] = $this->display_count($text_output);

        return $links;
    }		
    // display number of total products found
    function display_count($text_output) {
        $to_num = ($this->number_of_rows_per_page * $this->current_page_number);
        if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows;

        $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1));

        if ($to_num == 0) {
            $from_num = 0;
        } else {
            $from_num++;
        }

        return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);
    }
}

	#echo '<pre>';
	#print_r ($_SESSION);
	#echo '</pre>';
?>